import { request } from '../../request/index'
import regeneratorRuntime from "../../lib/runtime/runtime"
Page({
  // 获取用户信息
  async handleGetUserInfo(e) {
    try {
      // 1. 用户信息
      const { iv, rawData, signature, encryptedData } = e.detail;
      // 2. 小程序登陆后的code
      let code = '';
      wx.login({
        timeout: 1000,
        success: (res) => {
          code = res.code;
        },
        fail: (err) => err
      });
      const params = { iv, rawData, signature, encryptedData, code };
      const { token } = await request({
        data: params,
        method: 'post',
        url: '/users/wxlogin'
      });
      // 注意: 如果你的不是企业账号, 是没有token的
      wx.setStorageSync('token', token)
      wx.navigateBack({ delta: 1 })
    } catch (error) {
      console.log(err);
    }
  }
})